package com.weetop.cfw.callback;

import com.google.android.material.appbar.AppBarLayout;

public abstract class AppBarLayoutStateChangeListener implements AppBarLayout.OnOffsetChangedListener {

    public class State{
        public static final int EXPANDED = 0;//展开
        public static final int COLLAPSED = 1;//折叠
        public static final int INTERMEDIATE = 2;//中间状态
    }
    private int mCurrentState = State.INTERMEDIATE;

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if(verticalOffset != 0){
            onOffsetChanged(appBarLayout);
        }
        if (verticalOffset == 0) {
            if (mCurrentState != State.EXPANDED) {
                onStateChanged(appBarLayout, State.EXPANDED);
            }
            mCurrentState = State.EXPANDED;
        } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
            if (mCurrentState != State.COLLAPSED) {
                onStateChanged(appBarLayout, State.COLLAPSED);
            }
            mCurrentState = State.COLLAPSED;
        } else {
            if (mCurrentState != State.INTERMEDIATE) {
                onStateChanged(appBarLayout, State.INTERMEDIATE);
            }
            mCurrentState = State.INTERMEDIATE;
        }
    }

    public void onStateChanged(AppBarLayout appBarLayout, int state){

    };

    //发生了偏移
    public abstract void onOffsetChanged(AppBarLayout appBarLayout);
}
